package net.openl10n.mdf;

public final class ReferenceId{

	private final DocumentId documentId;
	private final PartId partId;
	private final int hashCode;
	
	public ReferenceId(DocumentId documentId, PartId partId) {
		if(documentId == null)
			throw new IllegalArgumentException("documentId cannot be null");
		this.documentId = documentId;
		if(partId == null)
			throw new IllegalArgumentException("partId cannot be null");
		this.partId = partId;
		this.hashCode = generateHashCode();
	}
	
	public final DocumentId getDocumentId(){
		return documentId;
	}
	
	public final PartId getPartId(){
		return partId;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if(obj == this) return true;
		if (!(obj instanceof ReferenceId) ) return false;
		return this.documentId.equals( ( (ReferenceId)obj ).documentId )
			&& this.partId.equals( ( (ReferenceId)obj ).partId );
	}
	
	@Override
	public int hashCode() {
		return hashCode;
	}
	
	private int generateHashCode() {
	    int hash = 1;
	    hash = hash * 31 + partId.hashCode();
	    hash = hash * 31 + documentId.hashCode();
	    return hash;
	}

}
